<?php
/**
* @package Frontend-User-Access (com_frontenduseraccess)
* @version 3.0.8
* @copyright Copyright (C) 2008 Carsten Engel. All rights reserved.
* @license GPL versions free/trial/pro
* @author http://www.pages-and-items.com
* @joomla Joomla is Free Software
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

if(!$this->controller->fua_config['display_users'] && $this->controller->user_type!='Super Administrator'){
	die('Restricted access');
}

//header and nav
$this->controller->echo_header();

?>
<script language="JavaScript" type="text/javascript">

function check_limitstart(){
	ori_search = '<?php echo $this->search;?>';
	ori_joomla_group_filter = '<?php echo $this->joomla_group_filter; ?>';
	ori_usergroup_filter = '<?php echo $this->usergroup_filter; ?>';
	new_search = document.getElementById('search').value;
	new_joomla_group_filter = document.getElementById('joomla_group_filter').value;
	new_usergroup_filter = document.getElementById('usergroup_filter').value;
	if(ori_search!=new_search || ori_joomla_group_filter!=new_joomla_group_filter || ori_usergroup_filter!=new_usergroup_filter){
		document.adminForm.limitstart_needs_reset.value = 1;
	}else{
		document.adminForm.limitstart_needs_reset.value = 0;
	}	
	return true;
}

</script>
<form name="adminForm" method="post" action="index.php">
		<input type="hidden" name="option" value="com_frontenduseraccess" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="view" value="users" />
		<input type="hidden" name="limitstart_needs_reset" value="" />
		<?php echo JHTML::_( 'form.token' ); ?>	
<table id="fua_subheader">
	<tr>
		<td>
			<?php 
				echo '<p>';
				echo JText::_('NOT_SUPERADMIN');
				echo '.</p>';						
			?>
		</td>
		<td id="td_usergroup_selector">
			<?php
			echo JText::_('FILTER'); ?>:
			<input type="text" name="search" id="search" value="<?php echo $this->search;?>" class="text_area"  onchange="check_limitstart();" />
			<button onclick="check_limitstart();this.form.submit();"><?php echo JText::_('GO'); ?></button>
			<?php
			$selected = 'selected="selected"';
			echo JText::_('JOOMLAGROUP').': '; 
			echo '<select name="joomla_group_filter" id="joomla_group_filter" onchange="check_limitstart();this.form.submit();">';
			echo '<option value="">'.JText::_('ALL').'</option>';
			echo '<option value="18"';
			if($this->joomla_group_filter==18){
				echo $selected;
			}
			echo '>registered</option>';
			echo '<option value="19"';
			if($this->joomla_group_filter==19){
				echo $selected;
			}
			echo '>author</option>';
			echo '<option value="20"';
			if($this->joomla_group_filter==20){
				echo $selected;
			}
			echo '>editor</option>';
			echo '<option value="21"';
			if($this->joomla_group_filter==21){
				echo $selected;
			}
			echo '>publisher</option>';
			echo '<option value="23"';
			if($this->joomla_group_filter==23){
				echo $selected;
			}
			echo '>manager</option>';
			echo '<option value="24"';
			if($this->joomla_group_filter==24){
				echo $selected;
			}
			echo '>administrator</option>';
			echo '</select>';
			
			echo ' '.JText::_('USERGROUP').': '; 
			echo '<select name="usergroup_filter" id="usergroup_filter" onchange="check_limitstart();this.form.submit();">';
			echo '<option value="">'.JText::_('ALL').'</option>';
			//echo '<option value="none"> --- </option>';
			foreach($this->fua_usergroups as $usergroup){		
				echo '<option value="'.$usergroup->id.'"';
				if($usergroup->id==$this->usergroup_filter){
					echo $selected;
				}	
				echo '>'.$usergroup->name.'</option>';						
			}
			echo '</select>';
			?>
			&nbsp;<button onclick="document.getElementById('search').value='';document.getElementById('joomla_group_filter').value='';document.getElementById('usergroup_filter').value='';this.form.submit();"><?php echo JText::_('RESET'); ?></button>
		</td>
	</tr>
</table>		
<table class="adminlist">
	<tr>
		<th align="left">
			<?php echo JText::_('USER'); ?>
		</th>
		<th align="left">
			<?php echo JText::_('USERNAME'); ?>
		</th>
		<th align="left">
			<?php echo JText::_('EMAIL'); ?>
		</th>		
		<th align="left">
			<?php echo JText::_('JOOMLAGROUP'); ?>
		</th>		
		<th align="left">
			<?php echo JText::_('USERGROUP'); ?>					
		</th>
		<th align="left">
			id					
		</th>
	</tr>	

<?php
/*
echo 'limit='.$this->limit.'<br />';
echo 'limitstart='.$this->limitstart.'<br />';
echo 'total='.$this->total.'<br />';
*/

$k = 0;
for($i=0; $i < count( $this->fua_users ); $i++) {
	$row = $this->fua_users[$i];
	
	//$usergroupName = $this->model->getUsergroupName($row->fua_usergroup, $this->fua_usergroups);		
	echo '<tr class="row'.$k.'"><td width="25%">'.$row->username.'</td><td>'.$row->name.'</td><td><a href="mailto:'.$row->email.'">'.$row->email;
	echo '</a></td>';	
	echo '<td>';
	if($this->controller->fua_config['show_joomla_group_select']){
		echo '<select name="gid[]">';
			echo '<option value="18"';
			if($row->gid==18){
				echo ' selected="selected"';
			}
			echo '>Registered</option>';
			echo '<option value="19"';
			if($row->gid==19){
				echo ' selected="selected"';
			}
			echo '>Author</option>';	
			echo '<option value="20"';
			if($row->gid==20){
				echo ' selected="selected"';
			}
			echo '>Editor</option>';
			echo '<option value="21"';
			if($row->gid==21){
				echo ' selected="selected"';
			}
			echo '>Publisher</option>';				
			echo '<option value="23"';
			if($row->gid==23){
				echo ' selected="selected"';
			}
			echo '>Manager</option>';			
			echo '<option value="24"';
			if($row->gid==24){
				echo ' selected="selected"';
			}
			echo '>Administrator</option>';		
		echo '</select>';
	}else{		
		if($row->gid==18){
			echo 'Registered';
		}else if($row->gid==19){
			echo 'Author';
		}else if($row->gid==20){
			echo 'Editor';		
		}else if($row->gid==21){
			echo 'Publisher';
		}else if($row->gid==23){
			echo 'Manager';		
		}else if($row->gid==24){
			echo 'Administrator';
		}
	}		
	echo '</td>';	
	echo '<td>';	
	echo '<select name="usergroup[]">';
	echo '<option value="0"> --- </option>';
	foreach($this->fua_usergroups as $fua_usergroup){
		if($fua_usergroup->id==$row->fua_usergroup){
			$selected = ' selected="selected"';
		}else{
			$selected = '';
		}		
		echo '<option value="'.$fua_usergroup->id.'" '.$selected.'>'.$fua_usergroup->name.'</option>';						
	}				
	echo '</select>';
	echo '</td>';
	echo '<td>';
	echo '<input type="hidden" name="user_id[]" value="'.$row->id.'" />';
	echo $row->id;
	echo '</td>';	
	echo '</tr>';
	
	if($k==1){
		$k = 0;
	}else{
		$k = 1;
	}
}
if(count($this->fua_users)==0){
	echo '<tr><td colspan="6">'.JText::_('NOUSERS').' <a href="index2.php?option=com_users&task=view">user manager</a>.</td></tr>';
}else{
	echo '<tfoot><tr><td colspan="6">'.$this->pagination->getListFooter().'</td></tr></tfoot>';
	
}
?>
	
</table>
</form>
<?php

$this->controller->display_footer();
?>